package com.company;


/**
 * 根据code构建不同的实现对象
 * @date : 2022/11/25 23:39
 */

public class P032_ObjectOrientedSelect {

    public static void main(String[] args) {
        select(1);
        select(2);
    }

    public static void select(int code) {
        Fruit fruit;
        switch (code) {
            case 1:
                fruit = new Apple();
                break;
            case 2:
            default:
                fruit = new Banana();
        }
        fruit.eat();
    }


    public interface Fruit {

        void eat();

    }

    public static class Apple implements Fruit {

        @Override
        public void eat() {
            System.out.println("eat apple");
        }
    }

    public static class Banana implements Fruit {

        @Override
        public void eat() {
            System.out.println("eat banana");
        }
    }
}
